package com.proj.hsy;

import java.io.ByteArrayOutputStream;

import org.apache.commons.codec.binary.Base64;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

public class ImageUtil {

	/** 
	 * bitmap转为base64 
	 * @param bitmap 
	 * @return 
	 */  
	@SuppressLint("NewApi")
	public static String bitmapToBase64(Bitmap bitmap) {  
		 ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
		 String js_out ="";
	        try {
	            if (bitmap.compress(CompressFormat.JPEG, 80, jpeg_data)) {
	                byte[] code = jpeg_data.toByteArray();
	                byte[] output = Base64.encodeBase64(code);
	                js_out = new String(output);
	            }
	        } catch (Exception e) {
	            return js_out;
	        }
	        return js_out;
	}  
}
